home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1990: Night of the Living Disc / Night of the Living Disc.2mg / Dev.CD.5 / Tools / DTS.Samples / SC09Lister / Menu.c < prev    next >
Encoding:
C/C++ Source or Header  |  1990-05-25  |  4.7 KB  |  189 lines  |  [B0] Apple IIgs Source Code (0x000A)

  1. /**********************************************************************
  2. *
  3. * lister menu.c -- Version 3.0
  4. *
  5. * Developer Technical Support Apple II Sample Code
  6. *
  7. * Copyright (c)
  8. * Apple Computer, Inc.  1988-1990
  9. * All Rights Reserved.
  10. *
  11. * Written by Eric Soldan.
  12. *
  13. * This file contains the code which implements menus in the
  14. * lister program.
  15. *
  16. **********************************************************************/
  17.  
  18. #include <types.h>
  19. #include <window.h>
  20. #include <event.h>
  21. #include <menu.h>
  22. #include <desk.h>
  23. #include <intmath.h>
  24. #include <resources.h>
  25.  
  26. #include "lister.h"
  27.  
  28. void    appSetMenus();
  29. void    doMenuCommand();
  30.  
  31. /**********************************************************************/
  32.  
  33. void    doQuitItem()
  34. {
  35.     quitFlag++;
  36. }
  37.  
  38. /**********************************************************************/
  39.  
  40. void            setMItem(id, flag)
  41. unsigned int    id, flag;
  42. {
  43.     if (flag) EnableMItem(id);
  44.     else      DisableMItem(id);
  45. }
  46.  
  47. /**********************************************************************/
  48.  
  49. void    doAboutItem()
  50. {
  51.     WindowPtr       wptr, keepPort;
  52.     unsigned long   id;
  53.     unsigned int    item;
  54.  
  55.     zapLocals();
  56.  
  57.     keepPort = GetPort();
  58.  
  59.     wptr = NewWindow2(NULL, NULL, NULL, NULL, 2, AboutWindowID, rWindParam1);
  60.     if (!_toolErr) {
  61.         aboutWindow = wptr;
  62.         for (;;) {
  63.             id = fakeModalDialog(&event, NULL, NULL, NULL,
  64.                 fmdMenuSelect+
  65.                 fmdMenuKey+
  66.                 fmdDeskAcc+
  67.                 fmdUpdateAll
  68.             );
  69.             item = id;                              /* Get lo-word. */
  70.             if (id & 0x80000000L) {                 /* If menu command... */
  71.                 if (item == 255) {
  72.                     HiliteMenu(0, FileMenuID);      /* Nobody else is going to.       */
  73.                     break;                          /* If close, close the about box. */
  74.                 }
  75.                 doMenuCommand(id);
  76.                 if (quitFlag) break;
  77.             }
  78.             else if (item == 1) break;              /* ...else handle controls. */
  79.         }
  80.     
  81.         SetPort(keepPort);
  82.         CloseWindow(wptr);
  83.         aboutWindow = NULL;
  84.         appSetMenus();
  85.     }
  86. }
  87.  
  88. /**********************************************************************/
  89.  
  90. void            doMenuCommand(id)
  91. unsigned long   id;
  92. {
  93.     unsigned int    menuNum, itemNum;
  94.  
  95.     zapLocals();
  96.  
  97.     menuNum = HiWord(id) & 0x7FFF;
  98.     itemNum = LoWord(id);
  99.  
  100.     switch (itemNum) {
  101.  
  102.         case AboutItem:
  103.             HiliteMenu(0, AppleMenuID);     /* Unhighlight the menu title first. */
  104.             menuNum = 0;                    /* Don't unhilight again. */
  105.             doAboutItem();
  106.             break;
  107.  
  108.         case QuitItem:
  109.             doQuitItem();
  110.             break;
  111.  
  112.         case UndoItem:
  113.         case CutItem:
  114.         case CopyItem:
  115.         case PasteItem:
  116.         case ClearItem:
  117.         case CloseItem:
  118.             break;
  119.  
  120.         case OpenFileItem:
  121.             getFileName(&file, 64, 30, "\pDon't think.  Just pick one.", NULL, NULL);
  122.             break;
  123.  
  124.         case ChoosePrinterItem:
  125.             PrChooser();
  126.             break;
  127.  
  128.         case PageSetupItem:
  129.             prRecHandler(0);                    /* PrStlDialog. */
  130.             break;
  131.  
  132.         case PrintItem:
  133.             doPrint();
  134.             break;
  135.     }
  136.  
  137.     if (menuNum) HiliteMenu(0, menuNum);        /* Unhighlight the menu title. */
  138. }
  139.  
  140. /**********************************************************************/
  141.  
  142. void    setupMenus()
  143. {
  144.     /* Procedure to install our menu titles and their items in the system menu
  145.     ** bar and to redraw it so we can see them.
  146.     */
  147.  
  148.     SetSysBar(NewMenuBar2(refIsResource, 0x0001L, NULL));
  149.     SetMenuBar(NULL);
  150.     
  151.     FixAppleMenu(AppleMenuID);              /* Add DAs to apple menu     */
  152.     FixMenuBar();                           /* Set sizes of menus        */
  153.     DrawMenuBar();                          /* ...and draw the menu bar! */
  154.  
  155.     DisableMItem(UndoItem);
  156.     fmdSetMenuProc(appSetMenus);
  157. }
  158.  
  159. /**********************************************************************/
  160.  
  161. void    appSetMenus()
  162. {
  163.     unsigned int    about, tabs, frontIsDA, i;
  164.  
  165.     zapLocals();
  166.  
  167.     about = tabs = frontIsDA = 0;
  168.  
  169.     if (aboutWindow) about++;
  170.     if (tabsWindow)  tabs++;
  171.     if (GetWKind(FrontWindow()) & 0x8000) frontIsDA++;
  172.  
  173.     setMItem(AboutItem, !about);
  174.         /* If about isn't already open, then allow it to be opened. */
  175.  
  176.     i = about | frontIsDA;
  177.     setMItem(CloseItem, i | tabs);
  178.         /* If we have an about box, tabs window, or DA, then allow close. */
  179.  
  180.     i = !i;     /* i is true if front window is main or tabs window. */
  181.  
  182.     setMItem(OpenFileItem, i);
  183.     setMItem(ChoosePrinterItem, i);
  184.     setMItem(PageSetupItem, i);
  185.     setMItem(PrintItem, (i) && (file.pathRef));
  186.  
  187.     if (!frontIsDA) DisableMItem(UndoItem);
  188. }
  189.